/**
 * 作者: hxl
 * 日期: 2025-05-30 17:21:59
 * 备注: 用户联盟乱斗商店数据表
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserUnionScuffleShop;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserUnionScuffleShopModel extends BaseModel implements Model {
    public static final String LISTKEY = "group_list_key.shop_id";
    public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
    public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
    public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

    protected long id; // 玩家id
    protected long actId; // 战斗id
    protected long userId; // 玩家id
    protected int shopId; // 商店id
    protected int buyNum; // 总战力 (活动购买次数)
    protected String groupListKey = ""; // 分组key
    protected int dayBuyNum; // 每日购买次数
    protected long dayResetTime; // 每日重置时间

    public void reset() {
    }

    protected String getKey() {
        return "UserUnionScuffleShop." + groupListKey + "." + shopId;
    }

    protected String getListKey() {
        return "UserUnionScuffleShop." + groupListKey;
    }

    protected String getListItemKey() {
        return shopId + "";
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public void setTableId() {
        putId(incrTableId("user_union_scuffle_shop"));
    }

    public JsonObject insert() {
        return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    public void delete() {
        super.delete(getKey(), id, UPDATE_DB_TYPE, userId, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    /**
     * 根据入库类型更新
     */
    public JsonObject update() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, userId, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入队列
     */
    public JsonObject updateQueueNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    public JsonObject getAllObj(){
        JsonObject obj = new JsonObject();
        obj.put("id", id); // 玩家id
        obj.put("actId", actId); // 战斗id
        obj.put("userId", userId); // 玩家id
        obj.put("shopId", shopId); // 商店id
        obj.put("buyNum", buyNum); // 总战力 (活动购买次数)
        obj.put("groupListKey", groupListKey); // 分组key
        obj.put("dayBuyNum", dayBuyNum); // 每日购买次数
        obj.put("dayResetTime", dayResetTime); // 每日重置时间
        return obj;
    }

    public PBUserUnionScuffleShop.Builder takeInitBuilder() {
        PBUserUnionScuffleShop.Builder sb = PBUserUnionScuffleShop.newBuilder();
        if (shopId != 0) {
            sb.setShopId(shopId);
        }
        if (buyNum != 0) {
            sb.setBuyNum(buyNum);
        }
        if (dayBuyNum != 0) {
            sb.setDayBuyNum(dayBuyNum);
        }
        return sb;
    }

    public PBUserUnionScuffleShop.Builder takeBuilder() {
        if (updateObj == null || updateObj.isEmpty()) {
            return takeInitBuilder();
        }
        PBUserUnionScuffleShop.Builder sb = PBUserUnionScuffleShop.newBuilder();
        if (isFieldUpdate("shopId")) {
            sb.setShopId(shopId);
        }
        if (isFieldUpdate("buyNum")) {
            sb.setBuyNum(buyNum);
        }
        if (isFieldUpdate("dayBuyNum")) {
            sb.setDayBuyNum(dayBuyNum);
        }
        return sb;
    }

    public long getId() {
        return id;
    }

    public void putId(long id) {
        if (this.id != id) {
            this.id = id;
            updateRedisHashField(getKey(), "id", this.id);
        }
    }

    public void addId(long value) {
        this.id += value;
        updateRedisHashField(getKey(), "id", this.id);
    }

    public long getActId() {
        return actId;
    }

    public void putActId(long actId) {
        if (this.actId != actId) {
            this.actId = actId;
            updateRedisHashField(getKey(), "actId", this.actId);
        }
    }

    public void addActId(long value) {
        this.actId += value;
        updateRedisHashField(getKey(), "actId", this.actId);
    }

    public long getUserId() {
        return userId;
    }

    public void putUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            updateRedisHashField(getKey(), "userId", this.userId);
        }
    }

    public void addUserId(long value) {
        this.userId += value;
        updateRedisHashField(getKey(), "userId", this.userId);
    }

    public int getShopId() {
        return shopId;
    }

    public void putShopId(int shopId) {
        if (this.shopId != shopId) {
            this.shopId = shopId;
            updateRedisHashField(getKey(), "shopId", this.shopId);
        }
    }

    public void addShopId(int value) {
        this.shopId += value;
        updateRedisHashField(getKey(), "shopId", this.shopId);
    }

    public int getBuyNum() {
        return buyNum;
    }

    public void putBuyNum(int buyNum) {
        if (this.buyNum != buyNum) {
            this.buyNum = buyNum;
            updateRedisHashField(getKey(), "buyNum", this.buyNum);
        }
    }

    public void addBuyNum(int value) {
        this.buyNum += value;
        updateRedisHashField(getKey(), "buyNum", this.buyNum);
    }

    public String getGroupListKey() {
        return groupListKey;
    }

    public void putGroupListKey(String groupListKey) {
        if (!this.groupListKey.equals(groupListKey)) {
            this.groupListKey = groupListKey;
            updateRedisHashField(getKey(), "groupListKey", this.groupListKey);
        }
    }

    public int getDayBuyNum() {
        return dayBuyNum;
    }

    public void putDayBuyNum(int dayBuyNum) {
        if (this.dayBuyNum != dayBuyNum) {
            this.dayBuyNum = dayBuyNum;
            updateRedisHashField(getKey(), "dayBuyNum", this.dayBuyNum);
        }
    }

    public void addDayBuyNum(int value) {
        this.dayBuyNum += value;
        updateRedisHashField(getKey(), "dayBuyNum", this.dayBuyNum);
    }

    public long getDayResetTime() {
        return dayResetTime;
    }

    public void putDayResetTime(long dayResetTime) {
        if (this.dayResetTime != dayResetTime) {
            this.dayResetTime = dayResetTime;
            updateRedisHashField(getKey(), "dayResetTime", this.dayResetTime);
        }
    }

    public void addDayResetTime(long value) {
        this.dayResetTime += value;
        updateRedisHashField(getKey(), "dayResetTime", this.dayResetTime);
    }

}